package com.example.demo.core.util;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil;
import com.example.demo.core.exception.BizException;

import java.util.Collection;
import java.util.Map;

public class AssertUtils {

    public static void isTrue(boolean expression, String message) {
        Assert.isTrue(expression, () -> new BizException(message));
    }

    public static void isFalse(boolean expression, String message) {
        Assert.isTrue(!expression, () -> new BizException(message));
    }

    public static void isNull(Object obj, String message) {
        Assert.isTrue(obj == null, () -> new BizException(message));
    }

    public static void notNull(Object obj, String message) {
        Assert.isTrue(obj != null, () -> new BizException(message));
    }

    public static void isBlank(String text, String message) {
        Assert.isTrue(StrUtil.isBlank(text), () -> new BizException(message));
    }

    public static void notBlank(String text, String message) {
        Assert.isTrue(StrUtil.isNotBlank(text), () -> new BizException(message));
    }

    public static void isEmpty(Collection<?> collection, String message) {
        Assert.isTrue(CollectionUtil.isEmpty(collection), () -> new BizException(message));
    }

    public static void isEmpty(Map<?, ?> map, String message) {
        Assert.isTrue(CollectionUtil.isEmpty(map), () -> new BizException(message));
    }

    public static void isEmpty(Object[] array, String message) {
        Assert.isTrue(array == null || array.length == 0, () -> new BizException(message));
    }

    public static void notEmpty(Collection<?> collection, String message) {
        Assert.isTrue(CollectionUtil.isNotEmpty(collection), () -> new BizException(message));
    }

    public static void notEmpty(Map<?, ?> map, String message) {
        Assert.isTrue(CollectionUtil.isNotEmpty(map), () -> new BizException(message));
    }

    public static void notEmpty(Object[] array, String message) {
        Assert.isTrue(array != null && array.length > 0, () -> new BizException(message));
    }

}
